package com.zeng.stpro.modules.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zeng.stpro.commons.controller.AbstractBaseController;
import com.zeng.stpro.commons.utils.R;
import com.zeng.stpro.modules.app.bean.SysRole;
import com.zeng.stpro.modules.app.bean.SysRolePermission;
import com.zeng.stpro.modules.app.service.SysRolePermissionService;
import com.zeng.stpro.modules.app.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/admin/role")
public class SysRoleController extends AbstractBaseController {

    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private SysRolePermissionService sysRolePermissionService;

    @GetMapping(value = "/{id}")
    public R findRoleById(@PathVariable Long id) {
        SysRole sysRole1 = sysRoleService.getById(id);
        System.out.println(sysRole1);
        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_code", "admin");
        SysRole sysRole2 = sysRoleService.getOne(queryWrapper);
        System.out.println(sysRole2);
        return R.ok().data("obj", sysRole1);
    }

    @GetMapping(value = "/ros/{roleid}")
    public R findPermissionIdListByRoleId(@PathVariable Long roleid) {
        List<Long> permissionIdList = sysRolePermissionService.findPermissionIdListByRoleId(roleid);
        return R.ok().data("permissionids", permissionIdList);
    }

}